﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IGolovkine.Core.Diagnostics;

namespace IGolovkine.ShoutCastRipper.Filters
{
    public class ContentTitleDuplicatesFilter : IContentTitleFilter
    {
        private IContentRepository _contentRepository;
        public ContentTitleDuplicatesFilter(IContentRepository contentRepository)
        {
            Debug.NotDefault(() => contentRepository);
            _contentRepository = contentRepository;
        }

        public string Name
        {
            get { return "Duplicate Titles Filter"; }
        }

        public ContentTitleFilterResult Process(string title)
        {
            string location = _contentRepository.GetContentLocation(title);
            if (location == null)
            {
                return new ContentTitleFilterResult(string.Format("'{0}' doesn't exist, accepting", title), true);
            }
            else
            {
                return new ContentTitleFilterResult(string.Format("Content with title already exists at '{0}'", location), false);

            }
        }
    }
}
